let nums = [100,4,200,1,3,2]

let longestConsecutive  = function(nums){
    // 创建哈希集合
    const numSet = new Set(nums);
    let longestStreak = 0;
    for(const num of numSet){
        if(numSet.has(num - 1)){
            continue;
        }
        // 当前数字是序列的起点，开始扩展序列
        let currentStreak = 1;
        let currentNum = num;
        while(numSet.has(currentNum + 1)){
            currentNum += 1; // 更新当前数字
            currentStreak += 1;
        }
        longestStreak = Math.max(longestStreak, currentStreak);
        
    }
    console.log(longestStreak)

    return longestStreak;
}
longestConsecutive(nums)